package server;

import java.util.ArrayList;
import java.util.List;

public class Game {

	private final int MAX_PLAYERS;
	List<Player> players;
	private final int BOARD_SIZE;
	private final boolean KERYO;
	private final int TIME;
	private final boolean TOUR;
	private final Player HOST;
	private boolean game_on = false;
	
	
	public Game(Player host, int maxPlayers, int board, int time, boolean keryo, boolean tour) {
		MAX_PLAYERS = maxPlayers;
		TIME = time;
		KERYO = keryo;
		TOUR = tour;
		BOARD_SIZE = board;
		HOST = host;
		players = new ArrayList<Player>(MAX_PLAYERS);
	}
	
	void addPlayer(Player p){
		synchronized (this) {
			if (players.size() == MAX_PLAYERS){
				System.err.print("Game already has max players");
			}
			else {
				players.add(p);
				p.joinGame(this);
			}
		}
	}
	
	boolean joinable() {
		if (game_on == false && players.size() < MAX_PLAYERS)
			return true;
		else
			return false;
	}
	
	String toXML() {
		return "<game host='" + HOST + "' size='" + BOARD_SIZE + "' players = '" + players.size() + "' maxplayers='" + MAX_PLAYERS + "' keryo= '" + KERYO + "' time='" + TIME + "' tour='" + TOUR + "' />";
	}
	
}
